package whf.framework.aop;

import java.lang.reflect.Method;

import whf.framework.exception.AuthorizationException;
import whf.framework.security.UserContext;
import whf.framework.util.ThreadContext;

/**
 * @author king
 * @create 2008-1-21 下午01:39:33
 * 
 */
public class ServiceMethodSecurityAdvice implements org.springframework.aop.MethodBeforeAdvice {

	/* (non-Javadoc)
	 * @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object)
	 */
	public void before(Method method, Object[] args, Object target) throws Throwable {
		UserContext userContext = ThreadContext.getUserContext();
		if(userContext != null && !userContext.hasFunctionPermission(target.getClass().getName(), method.getName())) {
			throw new AuthorizationException("No permission for:" + target.getClass().getName() +"." + method.getName());
		}
	}

}
